@echo off
title Valhalla MC
echo ===================================================
echo   Installing Eagle7z's Modpack with Shaders...
echo ===================================================
echo.

:: 1. Backup existing mods folder if it exists
if exist "%APPDATA%\.minecraft\mods\" (
    echo Existing mods folder detected.
    if exist "%APPDATA%\.minecraft\mods.old\" (
        echo Removing previous mods backup...
        rmdir /s /q "%APPDATA%\.minecraft\mods.old"
    )
    echo Backing up current mods to mods.old...
    ren "%APPDATA%\.minecraft\mods" "mods.old"
)

:: 2. Download and extract the main mods zip file
powershell -Command "New-Item -ItemType Directory -Force -Path \"$env:APPDATA\.minecraft\mods\"; echo 'Downloading mods...'; Invoke-WebRequest -Uri 'https://www.dropbox.com/scl/fi/ebgvbjrbg8zrq07dxg5mz/mods.zip?rlkey=7lmw1h0hgqujmd3hyofc3wat0&st=zvjq9dti&dl=1' -OutFile \"$env:APPDATA\.minecraft\mods\mods.zip\"; echo 'Extracting mods...'; Expand-Archive -Path \"$env:APPDATA\.minecraft\mods\mods.zip\" -DestinationPath \"$env:APPDATA\.minecraft\mods\" -Force; Remove-Item \"$env:APPDATA\.minecraft\mods\mods.zip\""

:: 3. Fix the nested folder issue automatically if it exists
if exist "%APPDATA%\.minecraft\mods\mods\" (
    echo Fixing folder nesting...
    move "%APPDATA%\.minecraft\mods\mods\*" "%APPDATA%\.minecraft\mods\" >nul
    rmdir "%APPDATA%\.minecraft\mods\mods"
)

:: 4. Backup existing shaderpacks folder if it exists
echo.
echo ===================================================
echo   Installing Photon Shaders...
echo ===================================================
echo.

if exist "%APPDATA%\.minecraft\shaderpacks\" (
    echo Existing shaderpacks folder detected.
    if exist "%APPDATA%\.minecraft\shaderpacks.old\" (
        echo Removing previous shaderpacks backup...
        rmdir /s /q "%APPDATA%\.minecraft\shaderpacks.old"
    )
    echo Backing up current shaderpacks to shaderpacks.old...
    ren "%APPDATA%\.minecraft\shaderpacks" "shaderpacks.old"
)

:: Create target directory cleanly
set "FINAL_SHADERS_DIR=%APPDATA%\.minecraft\shaderpacks"
mkdir "%FINAL_SHADERS_DIR%" 2>nul

:: Download your custom master shaders.zip package
echo Downloading shaders package...
powershell -Command "Invoke-WebRequest -Uri 'https://www.dropbox.com/scl/fi/k2qjk3n11vkn9ld4i21iz/shaders.zip?rlkey=fcqds4dxurqkhlragp26boj1q&st=szg8lokx&dl=1' -OutFile \"$env:APPDATA\.minecraft\shaderpacks\shaders.zip\""

:: Extract everything from shaders.zip right into the root of shaderpacks
echo Extracting shader files...
powershell -Command "Expand-Archive -Path \"$env:APPDATA\.minecraft\shaderpacks\shaders.zip\" -DestinationPath \"$env:APPDATA\.minecraft\shaderpacks\" -Force"

:: Delete the master shaders.zip container so only the extracted files remain
del /f /q "%FINAL_SHADERS_DIR%\shaders.zip"

:: 5. Advanced Optional Modpack Prompt
echo.
echo ===================================================
echo   Technical Add-ons
echo ===================================================
echo.
choice /M "Would you like to install the Advanced Pack as well?"
if errorlevel 2 goto :SkipAdvanced
if errorlevel 1 goto :InstallAdvanced

:InstallAdvanced
echo.
echo Downloading and adding Advanced Pack to mods...
powershell -Command "echo 'Downloading advanced pack...'; Invoke-WebRequest -Uri 'https://www.dropbox.com/scl/fi/unfnqbdjgqq0v1qxb0mtr/advanced.zip?rlkey=fyj61dxf775wijt7o38kr8rj2&st=0wbt9t8d&dl=1' -OutFile \"$env:APPDATA\.minecraft\mods\advanced.zip\"; echo 'Extracting advanced files...'; Expand-Archive -Path \"$env:APPDATA\.minecraft\mods\advanced.zip\" -DestinationPath \"$env:APPDATA\.minecraft\mods\" -Force; Remove-Item \"$env:APPDATA\.minecraft\mods\advanced.zip\""
goto :EndScript

:SkipAdvanced
echo.
echo Skipping Advanced Pack installation.
goto :EndScript

:EndScript
echo.
echo ===================================================
echo   SUCCESS! Installation Complete.
echo ===================================================
echo.
pause
